package com.lhj.bootdemo.thread;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ExecutorService;

/**
 * @author lhj
 * @version 1.0
 * @date 2022/4/25 4:42 下午
 * @description:
 */

@RestController
public class ThreadController {
    @Autowired
    private MyRunnable myRunnable;

    @RequestMapping("/hello")
    public String hello(@RequestBody  Map<String, String> map){
        ExecutorService executorPool = ThreadPoolUtil.getExecutorPool();
        myRunnable.setMap(map);
        System.out.println("当前线程的名字："+Thread.currentThread().getName());
        executorPool.execute(myRunnable);
        return "hello";
    }

    @RequestMapping("/hello1")
    public String hello1(@RequestBody  Map<String, String> map){
        ExecutorService executorPool = ThreadPoolUtil.getExecutorPool();
        myRunnable.setMap(map);
        System.out.println("当前线程的名字："+Thread.currentThread().getName());
        return "hello";
    }
}
